package com.yun.algorithmproblem.leetcode;

public class Leetcode547 {
    public int findCircleNum(int[][] isConnected) {
        int count = 0;
        boolean[] mark = new boolean[isConnected.length];
        for (int i = 0; i < isConnected.length; i++) {
            if (!mark[i]) {
                count++;
                dfs(isConnected,mark,i);
            }
        }
        return count;
    }

    private void dfs(int[][] isConnected, boolean[] mark, int i) {
        mark[i] = true;
        for (int j = 0; j < isConnected.length; j++) {
            if (isConnected[i][j] == 1 && !mark[j]) {
                dfs(isConnected,mark,j);
            }
        }
    }

    public static void main(String[] args) {
        int[][] isConnected={{1,1,0},{1,1,0},{0,0,1}};
        Leetcode547 obj=new Leetcode547();
        System.out.println(obj.findCircleNum(isConnected));
    }
}
